package com.ruoyi.web.controller.product;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MedicineStandard;
import com.ruoyi.system.service.IMedicineStandardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 中药材标准库库Controller
 * 
 * @author ruoyi
 * @date 2025-01-23
 */
@RestController
@RequestMapping("/system/standard")
public class MedicineStandardController extends BaseController
{
    @Autowired
    private IMedicineStandardService medicineStandardService;

    /**
     * 查询中药材标准库库列表
     */
    @PreAuthorize("@ss.hasPermi('system:standard:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicineStandard medicineStandard)
    {
        startPage();
        List<MedicineStandard> list = medicineStandardService.selectMedicineStandardList(medicineStandard);
        return getDataTable(list);
    }

    /**
     * 导出中药材标准库库列表
     */
    @PreAuthorize("@ss.hasPermi('system:standard:export')")
    @Log(title = "中药材标准库库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicineStandard medicineStandard)
    {
        List<MedicineStandard> list = medicineStandardService.selectMedicineStandardList(medicineStandard);
        ExcelUtil<MedicineStandard> util = new ExcelUtil<MedicineStandard>(MedicineStandard.class);
        util.exportExcel(response, list, "中药材标准库库数据");
    }

    /**
     * 获取中药材标准库库详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:standard:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(medicineStandardService.selectMedicineStandardById(id));
    }

    /**
     * 新增中药材标准库库
     */
    @PreAuthorize("@ss.hasPermi('system:standard:add')")
    @Log(title = "中药材标准库库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicineStandard medicineStandard)
    {
        return toAjax(medicineStandardService.insertMedicineStandard(medicineStandard));
    }

    /**
     * 修改中药材标准库库
     */
    @PreAuthorize("@ss.hasPermi('system:standard:edit')")
    @Log(title = "中药材标准库库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicineStandard medicineStandard)
    {
        return toAjax(medicineStandardService.updateMedicineStandard(medicineStandard));
    }

    /**
     * 删除中药材标准库库
     */
    @PreAuthorize("@ss.hasPermi('system:standard:remove')")
    @Log(title = "中药材标准库库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(medicineStandardService.deleteMedicineStandardByIds(ids));
    }
}
